import cv2
import numpy as np
import matplotlib.pyplot as plt

# 读取图像
img = cv2.imread("test.jpg", cv2.IMREAD_GRAYSCALE)  # 读取灰度图
assert isinstance(img, np.ndarray)

# 创建核结构，kernel必须是float32类型
kernel = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]], np.float32)  # 轮廓效果

# 进行卷积
img_ = cv2.filter2D(img, -1, kernel)

# 图片展示
cv2.namedWindow("img", cv2.WINDOW_NORMAL)
cv2.resizeWindow("img", 700, 450)

cv2.imshow("img", img_)
cv2.waitKey(0)
cv2.destroyAllWindows()
